package com.hongxin.nw.netty.model.analysis.info;

import com.hongxin.nw.netty.utils.FieldAnalysis;
import com.hongxin.nw.netty.values.TypeIdentif;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * @remark A.7请求下发计费模型数据
 * @author: GuoXiaolin
 * @date 2019/5/28 10:16
 * @Version 1.0
 * @Descibe
 */
@Slf4j
@Getter
@Setter
public class Mrena1_4 {

    private String co;//充电设备编号	压缩BCD码	8Byte	充电设备编号
    private String chargeIdentify;//充电接口标识	BIN码	1Byte	充电设备为一桩多充时用来标记接口号，一桩一充时此项为0。多个接口时顺序对每个接口进行编号

    private int idx = 0;
    private ByteBuf byteBuf;

    private Mrena1_4 subCo() {
//        this.co = substring(TypeIdentif.BYTE_CO.getbyteLength());
//        this.co = FieldAnalysis.analysisBCD(this.co);
//        return this;

//        int byteLength = TypeIdentif.BYTE_CO.getInt();
//        this.co = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
//        this.co = FieldAnalysis.analysisBCD(this.co);
//        this.idx += byteLength;

        this.co = FieldAnalysis.subCo(TypeIdentif.BYTE_CO.getInt(),idx,byteBuf);
        this.idx += TypeIdentif.BYTE_CO.getInt();
        return this;
    }
    private Mrena1_4 subChargeIdentify() {
//        this.chargeIdentify =  substring(TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getbyteLength());
//        this.chargeIdentify = FieldAnalysis.analysisBin(this.chargeIdentify);
//        return this;

//        int byteLength = TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getInt();
//        this.chargeIdentify = BinaryTools.subByteBuf(byteLength, idx, byteBuf);
//        this.chargeIdentify = FieldAnalysis.analysisBin(this.chargeIdentify);
//        this.idx += byteLength;



        this.chargeIdentify = FieldAnalysis.subGun(TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getInt(),idx,byteBuf);
        this.idx += TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getInt();
        return this;
    }
    public Mrena1_4 analysisStr(int idx, ByteBuf byteBuf) {
        this.idx = idx;
        this.byteBuf = byteBuf;

        return this.subCo().subChargeIdentify();
    }
    @Override
    public String toString() {
        return "Mrena1_4{" +
                "co='" + co + '\'' +
                ", chargeIdentify='" + chargeIdentify + '\'' +
                '}';
    }
}
